/*
 * Copyright (c) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

export const babylonBlob = '/*\n * Copyright (C) 2012-2014 by various contributors (see AUTHORS)\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n * \n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n * \n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n*/\n\nimport { reservedWords } from \"../util/identifier\";\nimport { getOptions } from \"../options\";\nimport Tokenizer from \"../tokenizer\";\n\nexport const plugins = {};\n\nexport default class Parser extends Tokenizer {\n  constructor(options, input) {\n    options = getOptions(options);\n    super(options, input);\n\n    this.options = options;\n    this.inModule = this.options.sourceType === \"module\";\n    this.input = input;\n    this.plugins = this.loadPlugins(this.options.plugins);\n    this.filename = options.sourceFilename;\n\n    // If enabled, skip leading hashbang line.\n    if (this.state.pos === 0 && this.input[0] === \"#\" && this.input[1] === \"!\") {\n      this.skipLineComment(2);\n    }\n  }\n\n  isReservedWord(word) {\n    if (word === \"await\") {\n      return this.inModule;\n    } else {\n      return reservedWords[6](word);\n    }\n  }\n\n  hasPlugin(name) {\n    return !!this.plugins[name];\n  }\n\n  extend(name, f) {\n    this[name] = f(this[name]);\n  }\n\n  loadPlugins(pluginList) {\n    const pluginMap = {};\n\n    if (pluginList.indexOf(\"flow\") >= 0) {\n      // ensure flow plugin loads last\n      pluginList = pluginList.filter((plugin) => plugin !== \"flow\");\n      pluginList.push(\"flow\");\n    }\n\n    if (pluginList.indexOf(\"estree\") >= 0) {\n      // ensure estree plugin loads first\n      pluginList = pluginList.filter((plugin) => plugin !== \"estree\");\n      pluginList.unshift(\"estree\");\n    }\n\n    for (const name of pluginList) {\n      if (!pluginMap[name]) {\n        pluginMap[name] = true;\n\n        const plugin = plugins[name];\n        if (plugin) plugin(this);\n      }\n    }\n\n    return pluginMap;\n  }\n\n  parse() {\n    const file = this.startNode();\n    const program = this.startNode();\n    this.nextToken();\n    return this.parseTopLevel(file, program);\n  }\n}\n';